package core.hmxchen.test.two;

import core.hmxchen.log.annotation.LogPrint;
import core.hmxchen.log.enums.Level;
import core.hmxchen.log.enums.Position;
import core.hmxchen.log.enums.Print;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @version v1.0.0
 * @ClassName LoginService
 * @Description TODO
 * @Author hmxchen
 * @Date 2021/9/5 21:47
 */
@Service
public class LoginService {
    //由于aop内部调用方法,切面会失效，采用注入一个代理对象，由代理对象进行调用内部方法
    @Autowired
    private LoginService _this;
    @LogPrint(biz = "获取登录凭证",level = Level.INFO,print = Print.DO_BEFORE_LOG,position = Position.ENABLED)
    public String loginUUID(String userName,String password){
        _this.checkUserName(userName);
        String oldPw = _this.getOldPwByUserName(userName);
        _this.checkPassword(oldPw,password);
        return _this.genUUID(userName);
    }
    @LogPrint(biz = "校验账户",level = Level.INFO,print = Print.DO_BEFORE_LOG,position = Position.ENABLED)
    public void checkUserName(String userName){}
    @LogPrint(biz = "获取账号存储的密码",level = Level.INFO,print = Print.DO_BEFORE_LOG,position = Position.ENABLED)
    public String getOldPwByUserName(String userName){ return "123456"; }
    @LogPrint(biz = "校验密码",level = Level.INFO,print = Print.DO_BEFORE_LOG,position = Position.ENABLED)
    public void checkPassword(String oldPw,String currentPw){
        if(!Objects.equals(oldPw,currentPw)){
            throw new IllegalArgumentException("密码不正确");
        }
    }
    @LogPrint(biz = "生成登录凭证",level = Level.INFO,print = Print.DO_BEFORE_LOG,position = Position.ENABLED)
    public String genUUID(String userName){return "login-uuid"; }

}
